import { fromJS } from "immutable";
import { TOPIC_LISTS, ADD_LIST, TOGGLR_SCROLL_SHOW } from "./types";
const defaultState = fromJS({
  topicList: [],
  articleList: [],
  recommendList: [],
  articPage: 1,
  showScroll: false
});
const changeHomeData = (state, action) => {
  return state.merge({
    topicList: fromJS(action.topicList),
    articleList: fromJS(action.articleList),
    recommendList: fromJS(action.recommendList)
  });
};

export default (state = defaultState, action) => {
  switch (action.type) {
    case TOPIC_LISTS:
      return changeHomeData(state, action);
    case ADD_LIST:
      return state.merge({
        articleList: state.get("articleList").concat(action.list),
        articPage: action.nextPage
      });
    case TOGGLR_SCROLL_SHOW:
      return state.set("showScroll", action.show);
    default:
      return state;
  }
};
